function CustomFun() {
}

var customFun = new CustomFun();

CustomFun.prototype.version = function () {
    return '0.0.1';
};

/**
 @description 通过包名启动应用。如果该包名对应的应用不存在，则返回false；否则返回true。
 @param       packageName {string} :应用包名
 @param       delay {number} :启动后等待时长，单位毫秒。默认5000
 @param       startNum {number} :重试次数。默认3
 @return      {boolean}:返回是否成功
 */
CustomFun.prototype.launchApp = function (packageName, delay, startNum) {
    let result = false;
    if (!delay) {
        delay = 3000;
    }
    if (!startNum) {
        startNum = 4;
    }
    const appState = utils.isAppExist('com.tencent.wework')
    // 判断 APP 是否安装
    if (appState) {
        toast("启动应用中...");
        // 判断应用是否在前台启动
        let selectors = text('工作台');
        let num = 0;
        while (num < startNum) {
            if (getRunningPkg() === packageName) {

                if (has(selectors)) {
                    let node = selectors.getOneNodeInfo(1000);
                    if (node) {
                        node.click()
                    }
                    toast('启动成功');
                }
                result = true;
                break;
            } else {
                utils.openApp(packageName);

                sleep(delay);
                num++;
            }
        }
    } else {
        toast("应用尚未安装");
    }
    return result;
};
